package com.gjy.reflect.ref;

import lombok.Data;
import org.junit.jupiter.api.Test;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-02-20 14:44:39
 */
public class RefTest {

    @Test
    public void test1() {
        RefUse ref = new RefUse();
        ref.setRef("eee");
        ReferenceQueue<RefUse> queue = new ReferenceQueue<>();
        WeakReference<RefUse> weak = new WeakReference<>(ref, queue);

        System.out.println("weak.get() = " + weak.get());
        System.out.println("queue.poll().get() = " + queue.poll());
    }

    @Data
    private static final class RefUse {
        private String ref;
    }
}
